﻿/*
Author:		Robert Hashemian (http://www.hashemian.com/)
Modified by:	Munsifali Rashid (http://www.munit.co.uk/)
Modified by:	Tilesh Khatri
*/

function StartCountDown(myDiv, myTargetDate) {
    var dthen = new Date(myTargetDate);
    var dnow = new Date();
    var ddiff = new Date(dthen - dnow);
    //alert("dthen: " + dthen + " dnow: " + dnow + " ddiff: " + ddiff);
    gsecs = Math.floor(ddiff.valueOf() / 1000);
    //alert("gsecs: " + gsecs);
    CountBack(myDiv, gsecs);
}

function Calcage(secs, num1, num2) {
    s = ((Math.floor(secs / num1)) % num2).toString();
    return (s);
}

function CountBack(myDiv, secs) {
    var DisplayStr;
    var s = Calcage(secs, 86400, 100000);
    var day = parseInt(s);
    //alert("day: " + day);
    var DisplayFormat = day == 0 ? "%%H%%:%%M%%:%%S%%" : "%%D%% ngày, %%H%%:%%M%%:%%S%%".replace(/%%D%%/g, day.toString());
    DisplayStr = DisplayFormat;
    DisplayStr = DisplayStr.replace(/%%H%%/g, Calcage(secs, 3600, 24));
    DisplayStr = DisplayStr.replace(/%%M%%/g, Calcage(secs, 60, 60));
    DisplayStr = DisplayStr.replace(/%%S%%/g, Calcage(secs, 1, 60));
    if (secs > 0) {
        document.getElementById(myDiv).innerHTML = DisplayStr;
        setTimeout("CountBack('" + myDiv + "'," + (secs - 1) + ");", 990);
    }
    else {
        document.getElementById(myDiv).innerHTML = "Auction Over";
    }
}